<?php

namespace app\model;

use think\Model;

class CompositionGoods extends Model
{
    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'composition_goods';
    public static function setGoodslist($data)
    {
        if (!empty($data)) {
            $goods = [];
            foreach ($data as $key => $vo) {
                $goodsdata = Goods::find($vo['goods_id']);
                if (!empty($goodsdata)) {
                    $goods[$key] = $goodsdata->toArray();
                    $goods[$key]['image'] = toimg($goods[$key]['image']);
                    $goods[$key]['is_main'] = $vo['is_main'];
                    if ($goods[$key]['is_main'] == 1) {
                        $goods[$key]['active'] = true;
                    } else {
                        $goods[$key]['active'] = false;
                    }
                }
            }
        }
        return $goods;
    }
}
